package app.netant.book.zzs5;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Zzs5Detail extends BaseDetail {

	public Zzs5Detail(String netSite) {
		super(netSite);
		this.preHref = "http://www.zzs5.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main .left .show_info tbody tr td.show_title h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("下载");
			if(idx>0){
				title = title.substring(0,idx).trim();
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main .left .show_info tbody tr td table.show_data tbody tr td");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx);
				String tagValue = tags.substring(idx+1);
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main .left .mod_box div div.show_content");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main .left .mod_box #downlink.show_downlink ul li a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("下载")>=0 || text.indexOf("解密")>=0 || text.indexOf("RAR")>=0){
				String href = parts.get(i).attr("href");
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
				
				if(href.endsWith(".rar")){
					String title = this.entity.getNovelName();
					this.entity.setNovelFullName(title+".rar");
				}
				
				break;
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".main .catpos a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Zzs5Detail detail = new Zzs5Detail("http://www.zzs5.com/txt/16539.html");
		detail.test();
	}



}
